#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
int n, k;
int arr[N];
int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> arr[i];
	sort(arr, arr + n);
	int left = 0, right = 0, ret = 1;
	while (right < n)
	{
		while (arr[right] - arr[left] > k)
		{
			left++;
		}
		ret = max(ret, right - left + 1);
		right++;
	}
	cout << ret << endl;
	return 0;
}